

<?php 	
function asorti($array)
{
   $copy = $array;
   
   $array = array_map('strtolower', $array);
   asort($array);
   
   foreach ($array as $index => $value) {
      $array[$index] = $copy[$index];
   }
   
   return $array;
}


if(isset($_SESSION["clientdownload"]) && $_SESSION["clientdownload"] != "")
{
	$dirPath = $_SESSION["clientdownload"]."/downloads/";
	
	// open the specified directory and check if it's opened successfully
	if ($handle = opendir($dirPath)) 
	{
	echo "<h2 class=\"header1\">".$_SESSION['clientname']."</h2>";
	   // keep reading the directory entries 'til the end
	   
	   $index = 0;
	   while (false !== ($file = readdir($handle))) 
	   {

	      // just skip the reference to current and parent directory
	      if ($file != "." && $file != "..") 
	      {
		 if (!is_dir("$dirPath/$file") && ! preg_match("/log/", $file)) 
		 {
		    $arrayOfFileName[$index] = $file;
		    $index++;
		    // found a file, do something with it?
		 }
	      }
	   }
	   // ALWAYS remember to close what you opened
	   closedir($handle);
	 }
	 //sort
	 asorti($arrayOfFileName);
	 foreach($arrayOfFileName as $key => $file)
		    echo "<a id=\"BodyMain\" href=./../phplib/download.php?fileName=". $file." >".$file."</a>".round(filesize("$dirPath/$file")/1024,2)." KB &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".date ("F d Y H:i:s.", filemtime("$dirPath/$file"))."<br>";
	 
	 
}
elseif(isset($_SESSION["clientdownload"]) && $_SESSION["clientdownload"] == "")
{
	echo "<h2 class=\"header1\">system has not been configured for them to download files.</h2>";
}
else
{
	echo "<h2 class=\"header1\">Configuration Error.</h2>";
}
echo "<div id=\"BodyMain\"> <br /><br /><br /><br /><br /><br/><br/><br/><br/><br/><br/><br/<br/><br/><br/><br/><br/><br/></div>"
?>
